package com.client.ryt.task.http.response;


import com.client.ryt.basic.BaseResponse;
import com.client.ryt.entity.exception.JsonException;
import com.client.ryt.entity.exception.RemoteDataException;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;


/**
 * Created by Administrator on 2014/7/12.
 */
public class TradeInfoResponse extends BaseResponse {

    String shopname;
    String followname;
    String tradeitem;
    String tradedesc;

    public String getShopname() {
        return shopname;
    }

    public String getFollowname() {
        return followname;
    }

    public String getTradeitem() {
        return tradeitem;
    }

    public String getTradedesc() {
        return tradedesc;
    }

    public TradeInfoResponse(){super(null);}
    public TradeInfoResponse(JSONObject json) {
        super(json);
        try {
            if(this.getIsSuccess()){
                JSONObject msg = json.getJSONObject("msg");
                if(msg.has("carduser")){
                    JSONObject carduser = msg.getJSONObject("carduser");
                    this.shopname = carduser.getString("shopname");
                    this.followname = carduser.getString("follow_nickname");
                }
                if(msg.has("card")){
                    JSONObject card = msg.getJSONObject("card");
                    this.tradedesc = card.getString("description");
                }
                if(msg.has("goods")){
                    JSONArray goods = msg.getJSONArray("goods");
                    String goodsString = "";
                    for(int i=0;i<goods.length();i++){
                        goodsString+=goods.getJSONObject(i).getString("title")+"\r\n";
                    }
                    this.tradeitem = goodsString;
                }
            }else{
                this.setBaseException(new RemoteDataException(json));
            }
        } catch (JSONException e) {
            this.setBaseException(new JsonException(e.getMessage()));
        }
    }

}
